console.log('---------------------接口interface混入--------------------')
interface Name {
  name: string
}
interface Age {
  age: number
}
interface Hobby {
  hobby: Array<any>
}
let myName: Name = {
  name: '奇奇'
}
let myAge: Age = {
  age: 16
}
let myHobby: Hobby = {
  hobby: ['打游戏', '按摩']
}
let hqq = Object.assign(myName, myAge, myHobby)
console.log('hqq:', hqq)
console.log('---------------------类Class混入--------------------')

// 类的混入
class A {
  flag: boolean
  //   constructor(flag: boolean) {
  //     this.flag = flag
  //   }
  changeFlag(): void {
    this.flag = !this.flag
  }
}
class B {
  name: string
  //   constructor(name: string) {
  //     this.name = name
  //   }
  getName(): string {
    return this.name
  }
}
class AandB implements A, B {
  flag: boolean = false
  name: string = '奇奇'
  changeFlag: () => void
  getName: () => string
  //   constructor(changeFlag: any, getName: any) {
  //     this.changeFlag = changeFlag
  //     this.getName = getName
  //   }
}

function mixins(curCl: any, itemCls: any[]) {
  itemCls.forEach((item) => {
    // console.log('item:', item)
    // console.log('prototype:', Object.getOwnPropertyNames(item.prototype))
    Object.getOwnPropertyNames(item.prototype).forEach((name) => {
      curCl.prototype[name] = item.prototype[name]
    })
  })
}

mixins(AandB, [A, B])
let andb = new AandB()
console.log(andb.getName())
console.log(andb.flag)
console.log(andb.changeFlag())
console.log(andb.flag)
